import { useFinishedProductInstockStore } from '@/store/FinishedProductInstock'
import tagRender from '@/components/aggridCellRenDerer/tagRender.vue'
import ButtionRender1 from '@/components/aggridCellRenDerer/buttionRender1.vue'


const store = useFinishedProductInstockStore()
const tableColumns = [
  // {
  //   headerCheckboxSelection: true,
  //   checkboxSelection: true,
  //   width: 50,
  //   showDisabledCheckboxes: false,
  //   pinned: 'left',
  // },
  {
    headerName: '公司',
    field: 'companyName',
    width: 150,
  },
  {
    headerName: '入库单号',
    field: 'stockInCode',
    width: 150,
  },
  {
    headerName: '仓库名称',
    field: 'warehouseName',
    width: 150,
  },
  {
    headerName: '库位',
    field: 'storageName',
    width: 150,
  },
  {
    headerName: '客户名称',
    field: 'customName',
    width: 150,
  },
  {
    headerName: '订单号',
    field: 'orderCode',
    width: 150,
  },
  {
    headerName: '客户订单号',
    field: 'customOrderCode',
    width: 150,
  },
  {
    headerName: '流转卡号',
    field: 'circulatCard',
    width: 150,
  },
  {
    headerName: '布号',
    field: 'clothCode',
    width: 150,
  },
  {
    headerName: '品名',
    field: 'brandName',
    width: 150,
  },
  {
    headerName: '色号',
    field: 'colorCode',
    width: 150,
  },
  {
    headerName: '色称',
    field: 'colorName',
    width: 150,
  },
  {
    headerName: '匹数',
    field: 'horseNo',
    width: 150,
  },
  {
    headerName: '重量',
    field: 'weight',
    width: 150,
  },
  {
    headerName: '布笼编号',
    field: 'shelveCode',
    width: 150,
  },
  {
    headerName: '来源单号',
    field: 'deliveryCode',
    width: 150,
  },
  {
    headerName: '开单日期',
    field: 'stockInDate',
    width: 150,
  },
  {
    headerName: '入库类型',
    field: 'stockInTypeTypeName',
    width: 150,
  },
  {
    headerName: '开单人员',
    field: 'createName',
    width: 150,
  },
  {
    headerName: '备注',
    field: 'remark',
    width: 150,
  },
  {
    headerName: '审核状态',
    field: 'auditState',
    width: 150,
    cellRenderer: tagRender,
    cellRendererParams: {
      styleClass: (params: any) => {
        return params.auditState == 0
          ? 'warning'
          : params.auditState == 1
            ? 'success' : ''
      },
      text: (params: any) => {
        return params.auditState == 0
          ? '待审核'
          : params.auditState == 1
            ? '审核通过' : ''
      },
      eltagSize: 0,
    },
    filterParams: {
      valueFormatter: function (params: any) {
        return params.value == '0'
          ? '待审核'
          : params.value == '1'
            ? '审核通过' : ''
      },
    }
  },
  {
    headerName: '审核人',
    field: 'auditName',
    width: 150,
  },
  {
    headerName: '审核日期',
    field: 'auditTime',
    width: 150,
  },
  {
    headerName: '操作',
    field: 'action',
    width: 150,
    pinned: 'right',
    cellRenderer: ButtionRender1,
    cellRendererParams: (params: any) => {
      return {
        buttonList: [
          {
            type: params.data.auditState==0?'primary':'info',
            text: '修改',
            typeName: 'el-button',
            show: true,
            disabled: params.data.auditState == 0 ? false : true,
            Callback: (data: any) => {
              return {
                rowData: data,
                emitString: 'FinishedProductInstock-edit'
              }
            },
          },
        ],
        eltagSize: 0,
      }
    }
  },
]

const tableColumns2 = [
  {
    headerCheckboxSelection: true,
    checkboxSelection: true,
    width: 50,
    showDisabledCheckboxes: false,
    pinned: 'left',
  },
  {
    headerName: '订单号',
    field: 'orderCode',
    width: 150,
    cellRenderer: {
      template: `
      <a-input v-model="rowData.orderCode" class="bacClass"   />
      `,
      setup(props: any) {
        const rowData = ref(props.params.data)
        return {
          rowData
        }
      }
    }
  },
  {
    headerName: '客户订单号',
    field: 'customOrderCode',
    width: 150,
    cellRenderer: {
      template: `
      <a-input v-model="rowData.customOrderCode" class="bacClass"   />
      `,
      setup(props: any) {
        const rowData = ref(props.params.data)
        return {
          rowData
        }
      }
    }
  },
  {
    headerName: '流转卡号',
    field: 'circulatCard',
    width: 150,
    cellRenderer: {
      template: `
      <a-input v-model="rowData.circulatCard" class="bacClass"   />
      `,
      setup(props: any) {
        const rowData = ref(props.params.data)
        return {
          rowData
        }
      }
    }
  },
  {
    headerName: '布号',
    field: 'clothCode',
    width: 150,
    cellRenderer: {
      template: `
      <a-input v-model="rowData.clothCode" class="bacClass"   />
      `,
      setup(props: any) {
        const rowData = ref(props.params.data)
        return {
          rowData
        }
      }
    }
  },
  {
    headerName: '品名',
    field: 'brandName',
    width: 150,
    cellRenderer: {
      template: `
      <a-input v-model="rowData.brandName" class="bacClass"   />
      `,
      setup(props: any) {
        const rowData = ref(props.params.data)
        return {
          rowData
        }
      }
    }
  },
  {
    headerName: '色号',
    field: 'colorCode',
    width: 150,
    cellRenderer: {
      template: `
      <a-input v-model="rowData.colorCode" class="bacClass"   />
      `,
      setup(props: any) {
        const rowData = ref(props.params.data)
        return {
          rowData
        }
      }
    }
  },
  {
    headerName: '色称',
    field: 'colorName',
    width: 150,
    cellRenderer: {
      template: `
      <a-input v-model="rowData.colorName" class="bacClass"   />
      `,
      setup(props: any) {
        const rowData = ref(props.params.data)
        return {
          rowData
        }
      }
    }
  },
  {
    headerName: '匹数',
    field: 'horseNo',
    width: 150,
    cellRenderer: {
      template: `
      <a-input-number v-model="rowData.horseNo" class="bacClass"  :precision="0" :min="0" :max="1000000"/>
      `,
      setup(props: any) {
        const rowData = ref(props.params.data)
        return {
          rowData
        }
      }
    }
  },
  {
    headerName: '重量',
    field: 'weight',
    width: 150,
    cellRenderer: {
      template: `
      <a-input-number v-model="rowData.weight" class="bacClass"  :precision="2" :min="0" :max="1000000"/>
      `,
      setup(props: any) {
        const rowData = ref(props.params.data)
        return {
          rowData
        }
      }
    }
  },
  {
    headerName: '布笼编号',
    field: 'shelveCode',
    width: 150,
    cellRenderer: {
      template: `
      <a-select
      popup-container="html"
      :loading="selectLoading"
      class="bacClass"
      :filter-option="false"
      allow-search
      :options="shelveCodeList"
      v-model.trim="rowData.shelveCode"
      @search="handleBlbhSearchs"
      allow-clear/>
      `,
      setup(props: any) {
        const rowData = ref(props.params.data)
        const shelveCodeList = ref(store.shelveCodeList)
        const handleBlbhSearchs = () => {
          console.log('搜索')
        }
        watch(() => store.shelveCodeList, (newVal) => {
          if (newVal.length == 0) {
            rowData.value.shelveCode = ''
            shelveCodeList.value = []
          } else {
            shelveCodeList.value = newVal
          }
        })
        return {
          rowData,
          handleBlbhSearchs,
          shelveCodeList,
        }
      }
    }
  },
  {
    headerName: '库位',
    field: 'storageName',
    width: 150,
    cellRenderer: {
      template: `
      <a-select
      popup-container="html"
      :loading="selectLoading"
      class="bacClass"
      :filter-option="false"
      allow-search
      :options="kwList"
      v-model.trim="rowData.storageName"
      @click="handleKwSearch('')"
      @search="handleKwSearch"
      allow-clear/>
      `,
      setup(props: any) {
        const rowData = ref(props.params.data)
        const kwList = ref(store.kwList)
        const handleKwSearch = (val: any) => {
          store.getKwList(val)
        }
        watch(() => store.kwList, (newVal) => {
          if (newVal.length == 0) {
            rowData.value.storageName = ''
            kwList.value = []
          } else {
            kwList.value = newVal
          }
        })
        return {
          rowData,
          kwList,
          handleKwSearch
        }
      }
    }
  },
]
export { tableColumns, tableColumns2 } 